<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改活动课内容')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
    <link th:href="@{/css/simplemde.min.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-courseContent-edit" th:object="${courseContent}">
            <input name="id" th:field="*{id}" type="hidden">

            <div class="form-group">
                <label class="col-sm-3 control-label">课程包ID：</label>
                <div class="col-sm-8">
                    <input name="vendorPackageId" class="form-control" type="text" th:field="*{vendorPackageId}"  required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">显示顺序：</label>
                <div class="col-sm-8">
                    <input name="orderNum" th:field="*{orderNum}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上传：</label>
                <div class="col-sm-8">
                    <a class="btn btn-success" onclick="onFile(1)" >
                        <i class="fa fa-plus"></i> 添加附件
                    </a>

                    <a class="btn btn-success" onclick="onFile(2)" >
                        <i class="fa fa-plus"></i> 上传封面
                    </a>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">封面：</label>
                <div class="col-sm-8">
                    <input name="cover" id="cover" th:field="*{cover}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{content}" id="content" name="content">
                    <textarea></textarea>
                </div>
            </div>


        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:src="@{/js/simplemde.min.js}"></script>
    <script th:inline="javascript">
        var simplemde = new SimpleMDE();
        var prefix = ctx + "system/courseContent";
        $("#form-courseContent-edit").validate({
            focusCleanup: true
        });
        setTimeout(function () {
            var content = $("#content").val();
            simplemde.value(content);
        }, 1500);
        function submitHandler() {
            if ($.validate.form()) {
                var testPlain = simplemde.value();
                $("#content").val(testPlain);
                $.operate.save(prefix + "/edit", $('#form-courseContent-edit').serialize());
            }
        }

        function onFile(type) {
            $('#upload').click();
            $('#type').val(type);
        }
        $('#upload').on('change', function(){
            var farmdate = new FormData();
            farmdate.append("file",$('#upload')[0].files[0]);
            farmdate.append("id",$('#id').val());
            $.ajax({
                type:"post",
                url:prefix+"/importImg",
                data:farmdate,
                contentType:false,
                processData:false,
                success:function (date) {
                    var testPlain = simplemde.value();
                    var type  = $('#type').val();
                    debugger;
                    if (type==1){
                        if (testPlain==""){
                            simplemde.value(date);
                        }else {
                            simplemde.value(testPlain+","+date);
                        }
                    }
                    if (type==2){
                        $('#cover').val(date);
                    }

                }
            })
        });
    </script>
</body>
</html>